﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Manage/TeacherMasterPage.master" AutoEventWireup="true" CodeFile="Course.aspx.cs" Inherits="Manage_Course" %>
<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
<script type="text/javascript" src="../js/jquery/jquery.ajaxfileupload.js"></script>
<script>
    $(function () {
        $("#dg tbody tr").hoverIntent(
        function () { $(this).children().css("background-color", "#F2F4F6"); },
        function () { $(this).children().css("background-color", "#FFFFFF"); }
    );
        $('#btnAddKnowledge').click(function (e) {
            $('#know-modal-content').modal({
                opacity: 55
            });
            return false;
        });
        $("#BtnImport").click(function (e) {
            $('#Import-modal-content').modal({
                opacity: 55
            });
            //253px
            $("#simplemodal-container").css("height", "260px");
            return false;
        });
    });
function addNew() {
    var kname ="";
    $("input[name='kname']").each(function(){
        var o = $(this).val();
        if(o!=="")
            kname += o.replace(/,/g,"") + ",";
    });
    if(kname==""){
        alert("<%= Resources.labels.mustonefield %>"); 
        return false;
    }
    
    $.ajax({
        type: "POST",
        cache: false,
        url: "Service/addKnowledge.aspx",
        data: "kname="+kname+"&cid=<%=cid %>",
        success: function(msg) {
            if (msg == "1") { alert("<%= Resources.labels.Add_ok %>"); }
            $.modal.close();
            window.location.href=location.href;
        },
        error:function(msg) {
            alert("<%= Resources.labels.Add_Err %>");
            $.modal.close();
        }
    });
}
function CancleNew(){
    $.modal.close();
}
function delConfirm(){
//    if (confirm("<%= Resources.labels.ConfirmDelete %>")) {
//        del();
//    }
    confirm("<%= Resources.labels.ConfirmDelete%>", function () {
        var qid = "";
        $("input:checked").each(function () {
            var o = $(this).val();
            if (o !== "")
                qid += o + ",";
        });
        if (qid == "") {
            //alert("<%= Resources.labels.PleaseCheckOne %>");
            $("#statusDel").html("&nbsp;<img src='../images/erro.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.PleaseCheckOne%>").css("color", "#FF0000").show();
            return false;
        }
        $.ajax({
            type: "POST",
            cache: false,
            url: "Service/delQuestion.aspx",
            data: "qid=" + qid + "&cid=<%=cid %>",
            beforeSend: function () {
                $(".statusDel").html("&nbsp;<img src='../images/loading16x16.gif' border=0 style='vertical-align:middle;' /><%= Resources.labels.PleaseWaiting%>").show();
            },
            success: function (msg) {
                if (msg == "1") {
                    $("#statusDel").html("&nbsp;<img src='../images/ok.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Del_ok%>").css("color", "#066606").show();
                    window.setTimeout(refresh, 2000);
                }
                else {
                    $("#statusDel").html("&nbsp;<img src='../images/erro.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Del_Fail%>").css("color", "#FF0000").show();
                }
            },
            error: function (msg) {
                $("#statusDel").html("&nbsp;<img src='../images/erro.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Del_Fail%>").css("color", "#FF0000").show();
            }
        });
    });
}
function confirm(message, callback) {
    $('#confirm').modal({
        closeHTML: "<a href='#' title='Close' class='modal-close'><%= Resources.labels.btnclose%></a>",
        //position: ["20%", ],
        overlayId: 'confirm-overlay',
        containerId: 'confirm-container',
        onShow: function (dialog) {
            var modal = this;
            $('.message', dialog.data[0]).append(message);
            // if the user clicks "yes"
            $('.yes', dialog.data[0]).click(function () {
                // call the callback
                if ($.isFunction(callback)) {
                    callback.apply();
                }
                // close the dialog
                //modal.close(); // or $.modal.close();
            });
        }
    });
}
function refresh() {
    window.location.href = window.location.href;
}
function del(){
    var qid ="";
    $("input:checked").each(function() {
        var o = $(this).val();
        if(o!=="")
            qid += o + ",";
    });
    if(qid==""){
        alert("<%= Resources.labels.PleaseCheckOne %>");
        return false;
    }
    //statusDel
    $.ajax({
        type: "POST",
        cache: false,
        url: "Service/delQuestion.aspx",
        data: "qid=" + qid + "&cid=<%=cid %>",
        beforeSend: function () {
            $(".statusDel").html("&nbsp;<img src='../images/loading16x16.gif' border=0 style='vertical-align:middle;' /><%= Resources.labels.PleaseWaiting%>").show();
        },
        success: function (msg) {
            if (msg == "1") {
                $("#statusDel").html("&nbsp;<img src='../images/ok.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Del_ok%>").css("color", "#066606");
                window.setTimeout(refresh, 2000);

            }
            else {
                $("#statusDel").html("&nbsp;<img src='../images/erro.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Del_Fail%>").css("color", "#FF0000");
            }
        },
        error: function (msg) {
            $("#statusDel").html("&nbsp;<img src='../images/erro.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Del_Fail%>").css("color", "#FF0000");
        }
//        success: function(msg) {
//            if (msg == "1") {
//                alert("<%= Resources.labels.Del_ok %>");
//                $("input:checked").each(function() {
//                    var o = $(this).val();
//                    $("#trq" + o).hide();
//                });
//            } else { alert("<%= Resources.labels.Del_Fail %>"); }
//        },
//        error: function(msg) {
//            alert("<%= Resources.labels.Del_Fail %>");
//        }
    });
}

</script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<table border="0" class="grid"  cellspacing="0" cellpadding="0" width="100%">
<thead>
    <tr>
        <th align=left><asp:Label ID="cname" runat="server" Text="Label"></asp:Label> </th>
    </tr>
</thead>
<tr>
    <td align=left>
    <a href="addQuestionCourse.aspx?cid=<%=cid %>" class="button"><%= Resources.labels.AddQuestion%></a>
    <a href='#' id='BtnImport' class="button"><%= Resources.labels.Import_list%></a>
    <a href='#'  class="button" onclick="delConfirm();return false;"><%= Resources.labels.Delete_Chk%></a>
    <a href='#' id="btnAddKnowledge" class='button'><%= Resources.labels.addKnowledge%></a>
    <a href='allquestion.aspx' id="A1" target="_blank" class='button'><%= Resources.labels.questionList%></a>
 
    </td>
</tr>
<tr>
<td>
    
    <table id="dg" class="grid" cellspacing="0" cellpadding="0" width="100%">
        <thead>
            <tr>
                <th width=6%><%= Resources.labels.select%></th>
                <th width=7%><%= Resources.labels.questiontype%></th>
                <th width=18%><%= Resources.labels.questiondiff%></th>
                <th><%= Resources.labels.questiontitle%></th>
                <th width=10%><%= Resources.labels.questionAnswer%></th>
                <th width=10%><%= Resources.labels.Edit%></th>
            </tr>
        </thead>
        
        <tbody>
        <asp:Repeater ID="rp" runat="server">
        <ItemTemplate>
            <tr id="trq<%# Eval("QuestionId")%>">
                <td><input id='chk<%# Eval("QuestionId")%>' name="chk" value='<%# Eval("QuestionId")%>' type="checkbox" /></td>
                <td><%# getQType(Eval("QuestiontypeId").ToString().Trim())%></td>
                <td><%# getQDiff(Eval("DifficultyId").ToString().Trim())%></td>
                <td>
                    <div style="overflow:hidden;width:100%;height:100%;border:solid #FF9900 0px;margin:2px;cursor:pointer;" onclick="getinfo('<%# Eval("QuestionId")%>')">
                    <%# getQtxt(Eval("QuestionContent").ToString())%>
                    </div>
                </td>
                <td><%# getAnswer(Eval("QuestionAnswer").ToString().ToUpper().Trim())%></td>
                <td>
                <a href="editquestion.aspx?id=<%# Eval("QuestionId")%>&cid=<%=cid %>" class="uiButton">
                <%= Resources.labels.modify%></a>
                </td>
            </tr>
        </ItemTemplate>
        </asp:Repeater>
        </tbody>
        
    	<tfoot>
    	    <tr>
    	        <td colspan=6>
    	        <webdiyer:aspnetpager id="AspNetPager1" runat="server" 
    	            EnableViewState="True"
    	            horizontalalign="Center" 
    	            PagingButtonSpacing="8px" 
                    showcustominfosection="Left" 
                    urlpaging="false" width="100%" 
                    ImagePath="~/images" 
                    NumericButtonType="Text" 
                    ButtonImageExtension="gif" 
                    ButtonImageNameExtension="n" 
                    DisabledButtonImageNameExtension="g" 
                    ShowNavigationToolTip="true" 
                    FirstPageText="<<" 
                    LastPageText=">>" NextPageText=">" PageSize="15" 
                    PrevPageText="<" SubmitButtonText="Go" 
                        onpagechanged="AspNetPager1_PageChanged"></webdiyer:aspnetpager>
    	        </td>
    	    </tr>
    	</tfoot>
    </table>

</td>
</tr>
</table>

<div class="btncontainer">
    <%= Resources.labels.search%>:
        <asp:DropDownList ID="QType" runat="server"></asp:DropDownList>
        <asp:DropDownList ID="QDifficulty" runat="server"></asp:DropDownList>
        <asp:DropDownList ID="QKnowledge" runat="server"></asp:DropDownList>
        <asp:TextBox ID="keywordTb" runat="server" Text="" ></asp:TextBox>
        <asp:Button ID="btnSearch" CssClass="button" runat="server" Text="查询" onclick="btnSearch_Click" />

<br />
</div>





<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td>
    <table class="grid" border="0" cellspacing="0" cellpadding="0" width="100%">
        <thead>
            <tr>
                <th><%= Resources.labels.count%></th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>
                    <asp:Label ID="LabTj" runat="server" Text="Label"></asp:Label></td>
            </tr>
        </tbody>
    	<tfoot>
    	    <tr>
    	        <th></th>
    	    </tr>
    	</tfoot>
    </table>
</td>
</tr>
</table>

<div id="know-modal-content">
	<div style="font-size:0.7em;"><%= Resources.labels.oneFiveKnowledge%></div>
	<p><input id="kname0" name="kname" style="width:325px;" type="text" /></p>
	<p><input id="kname1" name="kname" style="width:325px;" type="text" /></p>
	<p><input id="kname2" name="kname" style="width:325px;" type="text" /></p>
	<p><input id="kname3" name="kname" style="width:325px;" type="text" /></p>
	<p><input id="kname4" name="kname" style="width:325px;" type="text" /></p>
	<p>
    <input id="Button1" type="button" onclick="addNew()" class="button"  value="<%= Resources.labels.add%>" />
    <input id="Button2" type="button" onclick="CancleNew()" class="button" value="<%= Resources.labels.cancel%>" />
    </p>
</div>

<div id="Import-modal-content">
	<h4><%= Resources.labels.Import_list%></h4>
	<div>
	    <asp:DropDownList ID="QType2" runat="server"></asp:DropDownList> 
	    <asp:DropDownList ID="QDifficulty2" runat="server"></asp:DropDownList> 
	    <asp:DropDownList ID="QKnowledge2" runat="server"></asp:DropDownList>
        <br /><br />
	    <asp:FileUpload ID="fup" runat="server"  style="display:none;" /><input id="hidfup" type="hidden" value="" /><input type="button" class="button" onclick="HandleFileButtonClick();" value="Browse">
        <span id="statusImport" class="status" style="display:none;font-size:0.8em;padding-top:5px;">&nbsp;<img src='../images/loading16x16.gif' border=0 style='vertical-align:middle;' /><%= Resources.labels.PleaseWaiting%></span>
        <p>
            (<%= Resources.labels.onlyExcel%>) &nbsp;&nbsp;

            <a href="../template/1.xls" class="button" target=_blank><%= Resources.labels.SingleTemplate%></a>
            
            <a href="../template/2.xls" class="button" target=_blank><%= Resources.labels.MultipleTemplate%></a>
            
            <a href="../template/3.xls" class="button" target=_blank><%= Resources.labels.JudgmentTemplate%></a>

        </p>
    </div>
    <p></p>
</div>
<div id='confirm'>
	<div class='header'><span><%= Resources.labels.warning%></span></div>
	<div class='message'></div>
	<span id="statusDel" class="status" style="display:none;font-size:0.8em;padding-top:5px;">
     &nbsp;<img src="../images/loading16x16.gif" border=0 style="vertical-align:middle;" /><%= Resources.labels.PleaseWaiting%>
    </span>
	<div class='buttons'>
		<div class='no simplemodal-close'><%= Resources.labels.cancel%></div>
		<div class='yes'><%= Resources.labels.Delete%></div>
		
	</div>
</div>

<div id="question-modal-content">
	<p id="getquestionstatus">&nbsp;<img src="../images/loading16x16.gif" border=0 style="vertical-align:middle;" /><%= Resources.labels.PleaseWaiting%></p>
	<div id="getquestion_modal" style="text-align:left;"></div>
    <p><input id="Button3" type="button" onclick="CancleNew()" class="buttons" value="<%= Resources.labels.cancel%>" /></p>
</div>

<script>
    function HandleFileButtonClick() {
        document.getElementById("<%=fup. ClientID %>").click();
    }

    $(function () {
        $('#<%=fup. ClientID %>').change(function () {
            upload();
        });
    });
    function upload() {
        var result = false;
        var filepath = $("#<%=fup. ClientID %>").val();
        var extStart = filepath.lastIndexOf(".");
        var ext = filepath.substring(extStart, filepath.length).toUpperCase();
        if (ext == ".XLS") { result = true; }
        if (!result) {
            alert("<%= Resources.labels.onlyExcel%>"); return false;
        }
        $.ajaxFileUpload({
            url: '../ajaxUpload.aspx?random=' + Math.random(),
            secureuri: false,
            fileElementId: '<%=fup. ClientID %>',
            dataType: 'text',
            success: function (msg, status) {
                if (msg != '') {
                    $('#hidfup').val(msg);
                    ImportQuestion(msg);
                }
                else {
                    alert("<%= Resources.labels.mistakesAgain%>");
                }
            },
            error: function (msg, status, e) {
                alert("<%= Resources.labels.mistakesAgain%>"); $('#hidfup').val(""); $("#statusImport").hide();
            }

        });
        $('#<%=fup. ClientID %>').change(function () {
            upload();
        });
    }

    function ImportQuestion(f) {
        
        var cid = "<%=cid.ToString() %>"
        var xls = f; //$("#hidfup").val();
        var qtype = $("#<%=QType2.ClientID %>").val();
        var qdiff = $("#<%=QDifficulty2.ClientID %>").val();
        var qknow = $("#<%=QKnowledge2.ClientID %>").val();
        if (qknow == "") { alert("<%= Resources.labels.PleaseAddKnowledge%>"); return false }
        if (xls == "") { alert("<%= Resources.labels.mistakesAgain%>"); return false; }

        $.ajax({
            type: "POST", cache: false,
            url: "Service/importquestion.aspx",
            data: "cid=" + cid + "&qtype=" + qtype + "&qdiff=" + qdiff + "&qknow=" + qknow + "&filename=" + xls,
            beforeSend: function () {
                $("#statusImport").show();
            },
            success: function (msg) {
                if (msg != "") {
                    alert("<%= Resources.labels.importOkViewLog%>");
                    window.open("../logs/" + msg);
                    $.modal.close(); window.location.href = window.location.href;
                }
                else {
                    alert("<%= Resources.labels.mistakesAgain%>"); $.modal.close();
                }
            },
            error: function (msg) {
                alert("<%= Resources.labels.mistakesAgain%>"); //$.modal.close();
                $("#statusImport").hide();
            }
        });

    }
    function getinfo(id) {
        $('#question-modal-content').modal({
            opacity: 55, zIndex: 10, minHeight: 450,
            onOpen: function (dialog) {
                getQInfo(id);
                dialog.overlay.fadeIn('slow', function () {
                    dialog.data.hide();
                    dialog.container.fadeIn('fast', function () {
                        dialog.data.show(); //slideDown('slow');
                    });
                });
            }
        });
    }
    function getQInfo(id) {
        $.ajax({
            type: "get", cache: false,
            url: "Service/getQuestionInfo.aspx",
            data: "id=" + id,
            beforeSend: function () {
                $("#getquestionstatus").html("&nbsp;<img src='../images/loading16x16.gif' border=0 style='vertical-align:middle;' /><%= Resources.labels.PleaseWaiting%>").show();
            },
            success: function (msg) {
                if (msg != "") {
                    $("#getquestion_modal").html(msg);
                    $("#getquestionstatus").hide();
                }
                else {
                    $("#getquestionstatus").html("&nbsp;<img src='../images/erro.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Operate_Err%>").css("color", "#FF0000");
                }
            },
            error: function (msg) {
                $("#getquestionstatus").html("&nbsp;<img src='../images/erro.png' border=0 style='vertical-align:middle;' /><%= Resources.labels.Operate_Err%>").css("color", "#FF0000");

            }
        });
    }
</script>
</asp:Content>



